﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Livraria._Default" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<script type="text/C#" runat="server" language="c#">
    SqlConnection conn;
    public void Page_Load(Object Src, EventArgs E)
    {
        string strConnectionString = @"Data Source= srv-acd-sql;Initial Catalog=bdAsp_andre;Integrated Security=True";
        conn = new SqlConnection(strConnectionString);
        if (!IsPostBack)
        {
            BindDG();
        }
    }
    private void BindDG()
    {
        string sqlQuery = "SELECT nome 'Nome', categoria 'Categoria' FROM PRODUTO";
        SqlDataAdapter command = new SqlDataAdapter(sqlQuery, conn);
        DataSet ds = new DataSet();
        command.Fill(ds, "Produto");
        dglivraria.DataSource = ds.Tables["Produto"];

        dglivraria.DataBind();


    }
</script>

<head runat="server">
    <title>Livraria</title>
</head>
<body>
    <form id="Livraria" runat="server">
    <h3>
        Livraria do Mario
    </h3>
    <span id="Message" enableviewstate="false" runat="server" />
    <asp:DataGrid ID="dglivraria" runat="server" Width="400" ShowFooter="false">
        <Columns>
            <asp:EditCommandColumn EditText="Editar" UpdateText="Atualizar" CancelText="Cancel" />
        </Columns>
    </asp:DataGrid>
    
    <center>
        <asp:HyperLink ID="LinkButton1" runat="server" NavigateUrl="~/InserirProduto.aspx">Inserir</asp:HyperLink>&nbsp;
        <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/AlterarProduto.aspx">Alterar</asp:HyperLink>&nbsp;
        <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/DeletarProduto.aspx">Excluir</asp:HyperLink>&nbsp;
    </center>
    </form>
</body>
</html>
